<!DOCTYPE html>
<html lang="zh-CN" style="height:100%">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>Tqmall Api文档</title>
    <link href="/Public/frontapp/media/css/api-bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="/Public/frontapp/media/css/api-style.css" rel="stylesheet" type="text/css"/>
    <!--[if lt IE 9]>
    <script src="/Public/frontapp/media/js/html5shiv.min.js"></script>
    <script src="/Public/frontapp/media/js/respond.min.js"></script>
    <![endif]-->
</head>
<body style="height:100%">
<div class="container-fluid" style="background:white;height:100%;">
    <div class="row" style="height:100%;">
        <!--左侧导航start-->
        <div id="navbar" class="col-md-3"
             style="position:relative;background:#f5f5f5;padding:10px;height:100%;border-right:#ddd 1px solid;overflow-y:auto;">
            <div style="height:50px;font-size:30px;line-height:50px;">
                <a class="home" style="color:#000000;text-shadow:1px 0px 1px #666;text-decoration: none" href="">
                    <span class="glyphicon glyphicon-random" aria-hidden="true" style="width:40px;"></span>&nbsp;
                    <span style="position: relative;top:-3px;">Tqmall Api文档<span
                            style="font-size:12px;position:relative;top:-13px;">&nbsp;</span></span>
                </a>
            </div>
            <include file="Layouts:api_menu"/>
        </div>
        <!--左侧导航end-->
        <div id="mainwindow" class="col-md-9"
             style="height:100%;background:white;margin:0px;overflow-y:auto;padding:0px;">
            <!--顶部导航start-->
            <div class="textshadow"
                 style="font-size:16px;widht:100%;height:60px;line-height:60px;padding:0 16px 0 16px;;border-bottom:#ddd 1px solid">
            <span>
            <?php
            $length = sizeof($navigator);
            $count = 1;
            foreach ($navigator as $item) {
                if ($length != $count) {
                ?>
                <a href="{$item['url']}">{$item['name']}</a>&nbsp;->&nbsp;
                <?php
                } else {
                ?>
                <a href="{$item['url']}">{$item['name']}</a>
                <?php
                }
                $count++;
            }
            ?>
            </span>
        <span id="topbutton" style="float:right">
            <?php
                echo '欢迎您：' . $_SESSION['dept_name'] . '-' . $_SESSION['username'];;
            ?>
        </span>
            </div>
            <!--顶部导航end-->
            <!--主窗口start-->
            <div style="padding:16px;">
                <div style="border:1px solid #ddd">
                    <div style="background:#f5f5f5;padding:20px;position:relative">
                        <h4>修改接口<span style="font-size:12px;padding-left:20px;color:#a94442">注:"此色"边框为必填项</span></h4>

                        <div style="margin-left:20px;">
                            <form action="/home/api/edit?cate_id=<?php echo $_GET['cate_id']?>" method="post">
                                <h5>基本信息</h5>

                                <div class="form-group has-error">
                                    <div class="input-group">
                                        <div class="input-group-addon">接口编号</div>
                                        <input type="hidden" name="id" value="<?php echo $info['id']?>"/>
                                        <input type="text" class="form-control" name="num" placeholder="接口编号"
                                               value="<?php echo $info['num']?>" required="required">
                                    </div>
                                </div>
                                <div class="form-group has-error">
                                    <div class="input-group">
                                        <div class="input-group-addon">接口名称</div>
                                        <input type="text" class="form-control" name="name" placeholder="接口名称"
                                               value="<?php echo $info['name']?>" required="required">
                                    </div>
                                </div>
                                <div class="form-group has-error">
                                    <div class="input-group">
                                        <div class="input-group-addon">请求地址</div>
                                        <input type="text" class="form-control" name="url" placeholder="请求地址"
                                               value="<?php echo $info['url']?>" required="required">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <textarea name="des" class="form-control"
                                              placeholder="描述"><?php echo $info['des']?></textarea>
                                </div>
                                <div class="form-group" required="required">
                                    <select class="form-control" name="type">
                                        <?php
                                            $selected[0] = ($info['type'] == 'Dubbo') ? 'selected' : '';
                                            $selected[1] = ($info['type'] == 'GET') ? 'selected' : '';
                                            $selected[2] = ($info['type'] == 'POST') ? 'selected' : '';
                                        ?>
                                        <option value="Dubbo"
                                        <?php echo $selected[0]?>>Dubbo</option>
                                        <option value="GET"
                                        <?php echo $selected[1]?>>GET</option>
                                        <option value="POST"
                                        <?php echo $selected[2]?>>POST</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <h5>请求参数</h5>
                                    <?php
                                    if (!empty($info['raw_param']) && empty($info['parameter'])) {
                                        $raw = true;
                                    } else {
                                        $raw = false;
                                    }
                                    ?>
                                    <input type="radio" value="raw" <?php echo $raw ? 'checked' : '' ?> name="paramType[]" class="paramType">原始

                                    <?php
                                    if (empty($info['raw_param']) && !empty($info['parameter'])) {
                                        $form = true;
                                    } else {
                                        $form = false;
                                    }
                                    ?>
                                    <input type="radio" value="form" <?php echo $form ? 'checked' : '' ?> name="paramType[]" class="paramType">格式

                                    <textarea <?php echo $raw ? '' : 'style="display: none;"' ?> name="raw_param" id="raw_param" rows="3" class="form-control" placeholder="原始"><?php echo $info['raw_param']?></textarea>
                                    <table <?php echo $form ? '' : 'style="display: none;"' ?> class="table" id="parameter_table">
                                        <thead>
                                        <tr>
                                            <th class="col-md-3">参数名</th>
                                            <th class="col-md-2">必传</th>
                                            <th class="col-md-2">缺省值</th>
                                            <th class="col-md-4">描述</th>
                                            <th class="col-md-1">
                                                <button type="button" class="btn btn-success" onclick="add()">新增
                                                </button>
                                            </th>
                                        </tr>
                                        </thead>
                                        <tbody id="parameter">

                                        <?php $count = count($info['parameter']['name']);?>
                                        <?php for($i=0;$i<$count;$i++){ ?>
                                        <tr>
                                            <td class="form-group">
                                                <input type="text" class="form-control" name="p[name][]"
                                                       placeholder="参数名"
                                                       value="<?php echo $info['parameter']['name'][$i]?>">
                                            </td>
                                            <td>
                                                <?php
                                        $selected[0] = ($info['parameter']['type'][$i] == 'Y') ? 'selected' : '';
                                        $selected[1] = ($info['parameter']['type'][$i] == 'N') ? 'selected' : '';
                                        ?>
                                                <select class="form-control" name="p[type][]">
                                                    <option value="Y"
                                                    <?php echo $selected[0]?>>Y</option>
                                                    <option value="N"
                                                    <?php echo $selected[1]?>>N</option>
                                                </select>
                                            </td>
                                            <td><input type="text" class="form-control" name="p[default][]"
                                                       placeholder="缺省值"
                                                       value="<?php echo $info['parameter']['default'][$i]?>"></td>
                                            <td><textarea name="p[des][]" rows="1" class="form-control"
                                                          placeholder="描述"><?php echo $info['parameter']['des'][$i]?></textarea>
                                            </td>
                                            <td>
                                                <button type="button" class="btn btn-danger" onclick="del(this)">删除
                                                </button>
                                            </td>
                                        </tr>
                                        <?php } ?>

                                        </tbody>
                                    </table>
                                </div>
                                <div class="form-group">
                                    <h5>返回结果</h5>
                                    <textarea name="re" rows="3" class="form-control"
                                              placeholder="返回结果"><?php echo $info['re']?></textarea>
                                </div>
                                <div class="form-group">
                                    <h5>备注</h5>
                                    <textarea name="memo" rows="3" class="form-control"
                                              placeholder="备注"><?php echo $info['memo']?></textarea>
                                </div>
                                <button class="btn btn-success">Submit</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <!--主窗口end-->
        </div>
    </div>
</div>
<script src="/Public/frontapp/media/js/jquery-1.10.1.min.js"></script>
<script src="/Public/frontapp/media/js/jquery.cookie.min.js"></script>
<script src="/Public/frontapp/media/js/bootstrap.min.js"></script>
<script>
    function add() {
        var $html = '<tr>' +
                '<td class="form-group" >' +
                '<input type="text" class="form-control has-error" name="p[name][]" placeholder="参数名"></td>' +
                '<td>' +
                '<select class="form-control" name="p[type][]">' +
                '<option value="Y">Y</option> <option value="N">N</option>' +
                '</select >' +
                '</td>' +
                '<td>' +
                '<input type="text" class="form-control" name="p[default][]" placeholder="缺省值">' +
                '</td>' +
                '<td>' +
                '<textarea name="p[des][]" rows="1" class="form-control" placeholder="描述"></textarea>' +
                '</td>' +
                '<td>' +
                '<button type="button" class="btn btn-danger" onclick="del(this)">删除</button>' +
                '</td>' +
                '</tr >';
        $('#parameter').append($html);
    }
    function del(obj) {
        $(obj).parents('tr').remove();
    }
    $(function(){
        $('.paramType').click(function(){
            if ($(this).val() == 'raw') {
                $('#raw_param').show();
                $('#parameter_table').hide();
            } else {
                $('#parameter_table').show();
                $('#raw_param').hide();
            }
        });
    });
</script>
</body>
</html>